<?php

Yii::import("application.controllers.FrontendBaseController");

class SiteController extends FrontendBaseController
{
    /**
     * Declares class-based actions.
     */
    public function actions()
    {
        return array(
            // captcha action renders the CAPTCHA image displayed on the contact page
            'captcha'=>array(
                'class'=>'CCaptchaAction',
                'backColor'=>0xFFFFFF,
            ),
            // page action renders "static" pages stored under 'protected/views/site/pages'
            // They can be accessed via: index.php?r=site/page&view=FileName
            'page'=>array(
                'class'=>'CViewAction',
            ),
        );
    }

    /**
     * This is the default 'index' action that is invoked
     * when an action is not explicitly requested by users.
     */
    public function actionIndex()
    {
        // renders the view file 'protected/views/site/index.php'
        // using the default layout 'protected/views/layouts/main.php'
        $this->layout = '/layouts/home';
        $this->breadcrumbs = array( "" => "");
        $randUsers = UserFacade::getRandUsers(3);
        $randPosts = PostFacade::getRandPosts(3);
        $randPets = PetFacade::getRandPets(3);
        $randAdvts = AdvertisementFacade::getRandAdvts(4);
        $this->render( 'index', array(
                'randUsers' => $randUsers,
                'randPosts' => $randPosts,
                'randPets' => $randPets,
                'randAdvts' => $randAdvts,
            ) );
    }

    /**
     * This is the action to handle external exceptions.
     */
    public function actionError()
    {
        $this->breadcrumbs = array( "" => "");
        if($error=Yii::app()->errorHandler->error)
        {
            if(Yii::app()->request->isAjaxRequest)
                echo $error['message'];
            else
                $this->render('error', $error);
        }
    }

}